package lab02.test23;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Scanner;

/**
 * Created by Administrator on 2017-11-10.
 */
public class Test {
    public static void main(String[] args) {


        // 保存生日信息
        String birthday;

        System.out.println("Please input your birthday: ");
        Scanner scanner = new Scanner(System.in);
        birthday = scanner.nextLine();

        /**
         *
         *
         * 2017-11-20 -> long  time1 毫秒
         * 2017-11-10 -> long  time2 毫秒
         *
         * (time1 - time2)/(24*60*60*1000)
         */

        long time1 = 0;
        long time2 = 0;


        /**
         *
         * 实例化
         * Student chen = new Student();
         * Study study = new StudyImpl();
         * Calendar calendar = Calendar.getInstance();
         *
         *
         * 字符串 ---simpleDateFormat--> Date ---calendar----> long
         */

        try{

            // 如何将字符串转化为日期:Date对象
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-mm-dd");
            Date birthDate = simpleDateFormat.parse(birthday);
            Date currentDate = simpleDateFormat.parse("2017-11-10");

            // 如何将一个时间转换为long
            Calendar calendar = Calendar.getInstance();

            calendar.setTime(birthDate);
            time1 = calendar.getTimeInMillis();

            calendar.setTime(currentDate);
//            calendar.DAY_OF_WEEK
            time2 = calendar.getTimeInMillis();

            calendar.get(calendar.DAY_OF_WEEK);

        }catch (ParseException e){

        }finally {
            long days = (time1 - time2) / (24*60*60*1000);

            System.out.println("相差天数是： " + days);
        }
    }
}
